$(function(){
    var  commonYear = 2021,commonAreaCode = '330000';
    var areaSelectDatas = [
        { name:'浙江省',value:'330000'},
        { name:'杭州市',value:'330100'},
        { name:'宁波市',value:'330200'},
        { name:'温州市',value:'330300'},
        { name:'嘉兴市',value:'330400'},
        { name:'湖州市',value:'330500'},
        { name:'绍兴市',value:'330600'},
        { name:'金华市',value:'330700'},
        { name:'衢州市',value:'330800'},
        { name:'舟山市',value:'330900'},
        { name:'台州市',value:'331000'},
        { name:'丽水市',value:'331100'},
    ]
    layui.use('form', function(){
        var form = layui.form;
        setAreaSelects();
        form.render();
        form.on('select(areaCodeSelect)', function(data){
            commonAreaCode=data.value;
            init()
        });  
    });
    function setAreaSelects(){
        var html = '';
        $.each(areaSelectDatas,function(i,item){
            html += '<option value="'+item.value+'">'+item.name+'</option>'
        })
        $('[lay-filter="areaCodeSelect"]').html(html)
    }
    init();
    $('.sdqy [data-key]').on('click',function(){
        var type = $(this).attr('data-key');
        var numRow = {
            num: {title:'被投诉次数',field:'num'},
            rs: {title:'涉案人数',field:'rs'},
            je :{title:'涉案金额',field:'je'},
        }
        $$.alertTable({
            title: $(this).parent().siblings('.zb_title').text(),
            colsData: [[
                {title:'序号',type:'numbers'},
                {title:'企业名称',field:'aab004'},
                {title:'类型',field:'text'},
                numRow[type]
            ]],
            url: ajaxUrl + '/zjax/admin/Djg/zfjgsdqyTopList', //请求接口
            where: {
                aab301: commonAreaCode,
                year: commonYear,
                type: type
            },
            searchColumn: [],
            // toolFun: table.toolFun||undefined,
            rowClickFun: function (obj) {
                alertAJList('',{aab004: obj.data.aab004});
            }
        });
    });
    function init(){
        $$.ajaxRequest(ajaxUrl+'/zjax/admin/Djg/zfjggdqajlblqk',{
            year: commonYear,
            aab301: commonAreaCode
        },function(res){
            setBarOrLine('#ajblqkBarAndLine',{
                "unit":["件","%"],
                "categories": res.data.map(item=>item.ctname),
                "series":[
                    {"name":"案件量","type":"bar","yAxisIndex":0,"data": res.data.map(item=>item.ajl)},
                    {"name":"快调","type":"bar","yAxisIndex":0,"data": res.data.map(item=>item.kt)},
                    {"name":"立案","type":"bar","yAxisIndex":0,"data": res.data.map(item=>item.la)},
                    {"name":"办结率","type":"line","yAxisIndex":1,"data": res.data.map(item=>item.bjl)}
                ]
            },{
                twoYAxis:true
            },function(params){
                var index = params.dataIndex;
                // aab301
            });
        });
        $$.ajaxRequest(ajaxUrl+'/zjax/admin/Djg/zfjggdsssbqk',{
            year: commonYear,
            aab301: commonAreaCode
        },function(res){
            setBarOrLine('#smscqkBarAndLine',{
                "unit":["家","%"],
                "categories":  res.data.map(item=>item.ctname),
                "series":[
                    {"name":"书面审查","type":"bar","yAxisIndex":0,"data": res.data.map(item=>item.num)},
                    // {"name":"覆盖率","type":"line","yAxisIndex":1,"data": res.data.map(item=>item.fgl)}
                ]
            },{
                xAxisRotate: 45,
                twoYAxis:false,
                color: [
                    {color2:'',color1:'#15C0FF'},
                    {color2:'',color1:'#FFBD1E'},
                ]
            },function(params){
                var index = params.dataIndex;
                // aab301
                alertSMSCList(params.name,{
                    aab301: res.data[index].aab301
                })
            });
        });
        
        $$.ajaxRequest(ajaxUrl+'/zjax/admin/Djg/zfjgzxaj',{
            year: commonYear,
            aab301: commonAreaCode
        },function(res){
            initNewsList('#scrollNews',res.data,[
                {field: "abb277",title: "登记日期"},
                {field: "ajname",title: "案件名称"},
                // {field: "abb016",title: "案件编号"},
                {field: "abb010t",title: "主办监察员"},
                {field: "bb1004",title: "环节状态"},
            ],function(data,field){
                if(field == 'abb010t'){
                    alertAJList('',{abb010t: data.abb010t});
                }else if(field == 'ajname'){
                    alertAJDetails('',{id: data.abz001})
                }
            });
        });
        
        $$.ajaxRequest(ajaxUrl+'/zjax/admin/Djg/zfjgzfryajlpm',{
            year: commonYear,
            aab301: commonAreaCode
        },function(res){
            initNewsList('#ajlPHB',res.data,[
                {title:'排名',type:'pm'},
                {title:'姓名',field:'abb010t'},
                {title:'地区',field:'aab301s'},
                {title:'案件数量(件)',field:'num'},
            ],function(data){
                alertAJList('',{abb010t: data.abb010t});
            });
        })
        $$.ajaxRequest(ajaxUrl+'/zjax/admin/Djg/zfjgsdqyTopNum',{
            year: commonYear,
            aab301: commonAreaCode
        },function(res){
            $('[data-key="num"]').text(res.data.num);
            $('[data-key="je"]').text(res.data.je);
            $('[data-key="rs"]').text(res.data.rs);
        })
        $$.ajaxRequest(ajaxUrl+'/zjax/admin/Djg/zfjgsdqyBtnList',{
            year: commonYear,
            aab301: commonAreaCode
        },function(res){
            initNewsList('#sdqyPHB',res.data,[
                {title:'序号',type:'index'},
                {title:'企业名称',field:'aab004'},
                {title:'类型',field:'text'},
                {title:'案件数量(件)',field:'num'},
            ],function(data){
                alertAJList('',{aab004: data.aab004});
            });
        });
        
        
        
    }
    function alertAJList(title,params){
        $$.alertTable({
            title: title||'详情',
            colsData: [[
                {title:'序号',type:'numbers'},
                {field: "ajname",title: "案件名称"},
                {field: "abb016",title: "案件编号"},
                {field: "tsr",title: "投诉人"},
                {field: "btsr",title: "被投诉人"},
                {field: "aba003",title: "基本诉求"},
                {field: "abb012",title: "基本案情"},
                {field: "aba005",title: "立案依据"},
                {field: "abb277",title: "登记日期"},
                {field: "abb010t",title: "主办监察员"},
                {field: "abb011t",title: "协办监察员"},
                {field: "aba002",title: "案由"},
                {field: "aab301s",title: "管辖"},
                {field: "bb1004",title: "当前状态"}
            ]],
            url: ajaxUrl + '/zjax/admin/Djg/zfjglefttoplist', //请求接口
            where: Object.assign({
                type: 'jcaj',
                year: commonYear,
                aab301: commonAreaCode
            },params),
            searchColumn: [],
            rowClickFun: function (obj){
                alertAJDetails('',{id: obj.data.abz001})
            }
        })
    }
    function alertAJDetails(title,params){
        var ecm = $$.alert('axzs');
        $('#' + ecm).html(`
            <div class="title">案件详情</div>
            <div class="table_con">
            <div class="model">
                <div class="model_title">基本信息</div>
                <div class="model_content table"></div>
            </div>
            </div>
        `)
        $$.ajaxRequest(ajaxUrl + '/zjax/admin/Djg/zfjgjcajdetail',params,function(res){
            $$.title2Table('#'+ecm+' .table', [
                {field: "ajname",title: "案件名称",fitWidth: true},
                {field: "abb016",title: "案件编号"},
                {field: "aab301s",title: "管辖"},
                {field: "tsr",title: "投诉人"},
                {field: "btsr",title: "被投诉人"},
                {field: "bb1004",title: "当前状态"},
                {field: "abb277",title: "登记日期"},
                {field: "abb010t",title: "主办监察员"},
                {field: "abb011t",title: "协办监察员"},
                {field: "aba003",title: "基本诉求",fitWidth: true},
                {field: "abb012",title: "基本案情",fitWidth: true},
                {field: "aba005",title: "立案依据",fitWidth: true},
                {field: "aba002",title: "案由",fitWidth: true},
            ], res.data||{},2)
        })
    }
    function alertSMSCList(title,params){
        $$.alertTable({
            title: title||'详情',
            colsData: [[
                {title:'序号',type:'numbers'},
                {field: "aab004",title: "被检查单位名称"},
                {field: "abb369s",title: "书面审查状态"},
                // {field: "abb367",title: "检查材料"},
                {field: "abb057",title: "审查日期"},
                {field: "abb276",title: "主办监察员姓名"},
                {field: "abb363s",title: "审查类型"},
                {field: "aab301s",title: "所属管辖"},
            ]],
            url: ajaxUrl + '/zjax/admin/Djg/zfjglefttoplist', //请求接口
            where: Object.assign({
                type: 'smsc',
                year: commonYear,
                aab301: commonAreaCode
            },params),
            searchColumn: [],
            rowClickFun: function (obj){
                alertSMSCDetails(obj);
            }
        })
    }
    function alertSMSCDetails(obj){
        var ecm = $$.alert('axzs');
        $('#' + ecm).html(`
            <div class="title">案件详情</div>
            <div class="table_con">
            <div class="model">
                <div class="model_title">基本信息</div>
                <div class="model_content table"></div>
            </div>
            </div>
        `)
        $$.ajaxRequest(ajaxUrl + '/zjax/admin/Djg/zfjgsmscdetail',{id: obj.data.abz075},function(res){
            $$.title2Table('#'+ecm+' .table', [
                {field: "aab004",title: "被检查单位名称",fitWidth:true},
                {field: "abb369s",title: "书面审查状态"},
                {field: "abb367",title: "检查材料"},
                {field: "abb057",title: "审查日期"},
                {field: "abb276",title: "主办监察员姓名"},
                {field: "abb363s",title: "审查类型"},
                {field: "aab301s",title: "所属管辖"},
            ], res.data||{},2)
        })
    }
})
   